package com.ruoyi.web.controller.bookstore;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookstore.domain.BookSort;
import com.ruoyi.bookstore.service.IBookSortService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书籍分类Controller
 * 
 * @author ruoyi
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/bookstore/sort")
public class BookSortController extends BaseController
{
    @Autowired
    private IBookSortService bookSortService;

    /**
     * 查询书籍分类列表
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookSort bookSort)
    {
        startPage();
        List<BookSort> list = bookSortService.selectBookSortList(bookSort);
        return getDataTable(list);
    }

    /**
     * 导出书籍分类列表
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:export')")
    @Log(title = "书籍分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookSort bookSort)
    {
        List<BookSort> list = bookSortService.selectBookSortList(bookSort);
        ExcelUtil<BookSort> util = new ExcelUtil<BookSort>(BookSort.class);
        util.exportExcel(response, list, "书籍分类数据");
    }

    /**
     * 获取书籍分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bookSortService.selectBookSortById(id));
    }

    /**
     * 新增书籍分类
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:add')")
    @Log(title = "书籍分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookSort bookSort)
    {
        return toAjax(bookSortService.insertBookSort(bookSort));
    }

    /**
     * 修改书籍分类
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:edit')")
    @Log(title = "书籍分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookSort bookSort)
    {
        return toAjax(bookSortService.updateBookSort(bookSort));
    }

    /**
     * 删除书籍分类
     */
    @PreAuthorize("@ss.hasPermi('bookstore:sort:remove')")
    @Log(title = "书籍分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookSortService.deleteBookSortByIds(ids));
    }
}
